from rest_framework import serializers
from cars.serializers import CarLstSerl
from persons.serializers import PersonBriefSerl
import teacher
from teacher.serializers import TeacherBriefSerl, TeacherSerl
from visitor.models import VisitorModel
from visitor.models import VisitorApply
from visitor.models import VisitorApplyPerson
from visitor.models import VisitorApplyCar
from visitor.models import VisitorApplyVerify
from visitor.models import VisitorPerson
from visitor.models import VisitorCar
from visitor.models import VisitorTeacher


class VisitorSerl(serializers.ModelSerializer):
    updated = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S")

    class Meta:
        model = VisitorModel
        exclude = ("created",)


class VisitorBriefSerl(serializers.ModelSerializer):

    class Meta:
        model = VisitorModel
        fields = (
            "id",
            "dept",
            "name",
            "phone",
        )


class VisitorApplyLstSerl(serializers.ModelSerializer):
    visitor = VisitorBriefSerl()
    teacher = TeacherBriefSerl()
    STATUS_CHOISE = (
        (0, "被访者审核中"),
        (1, "上级审核中"),
        (2, "保卫处审核中"),
        (5, "审核完成"),
        (6, "审核失败"),
        (7, "访问中"),
        (8, "完成访问"),
        (9, "访问过期"),
    )
    status_text = serializers.ChoiceField(
        choices=STATUS_CHOISE, source="get_status_display"
    )
    when = serializers.DateTimeField(format="%m-%d %H:%M")

    class Meta:
        model = VisitorApply
        fields = (
            "id",
            "visitor",
            "teacher",
            "status",
            "status_text",
            "when",
        )


class VisitorApplyDetSerl(serializers.ModelSerializer):
    visitor = VisitorBriefSerl()
    teacher = TeacherBriefSerl()
    STATUS_CHOISE = (
        (0, "被访者审核中"),
        (1, "上级审核中"),
        (2, "保卫处审核中"),
        (5, "审核完成"),
        (6, "审核失败"),
        (7, "访问中"),
        (8, "完成访问"),
        (9, "访问过期"),
    )
    status_text = serializers.ChoiceField(
        choices=STATUS_CHOISE, source="get_status_display"
    )
    when = serializers.DateTimeField(
        format="%m-%d %H:%M", required=False, read_only=True
    )
    updated = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S")

    class Meta:
        model = VisitorApply
        exclude = ("created",)


class VisitorApplyBriefSerl(serializers.ModelSerializer):
    visitor = serializers.StringRelatedField()
    teacher = serializers.StringRelatedField()
    STATUS_CHOISE = (
        (0, "被访者审核中"),
        (1, "上级审核中"),
        (2, "保卫处审核中"),
        (5, "审核完成"),
        (6, "审核失败"),
        (7, "访问中"),
        (8, "完成访问"),
        (9, "访问过期"),
    )
    status_text = serializers.ChoiceField(
        choices=STATUS_CHOISE, source="get_status_display"
    )
    when = serializers.DateTimeField(format="%m-%d %H:%M")

    class Meta:
        model = VisitorApply
        fields = (
            "id",
            "visitor",
            "teacher",
            "status",
            "status_text",
            "when",
        )


class VisitorApplyPersonSerl(serializers.ModelSerializer):
    apply = VisitorApplyBriefSerl()
    person = PersonBriefSerl()

    class Meta:
        model = VisitorApplyPerson
        fields = (
            "id",
            "apply",
            "person",
        )


class VisitorApplyCarSerl(serializers.ModelSerializer):
    apply = VisitorApplyBriefSerl()
    car = CarLstSerl()

    class Meta:
        model = VisitorApplyCar
        fields = (
            "id",
            "apply",
            "car",
        )


class VisitorApplyVerifySerl(serializers.ModelSerializer):
    updated = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S")
    teacher = TeacherBriefSerl()
    STATGE_CHOISE = (
        (0, "被访者审核中"),
        (1, "上级审核中"),
        (2, "保卫处审核中"),
        (5, "审核完成"),
        (6, "审核失败"),
        (7, "访问中"),
        (8, "完成访问"),
        (9, "访问过期"),
    )
    stage_text = serializers.ChoiceField(
        choices=STATGE_CHOISE, source="get_stage_display"
    )
    STATUS_CHOISE = (
        (0, "待审核"),
        (1, "审核通过"),
        (2, "审核失败"),
    )
    status_text = serializers.ChoiceField(
        choices=STATUS_CHOISE, source="get_status_display"
    )

    class Meta:
        model = VisitorApplyVerify
        exclude = ("created",)


class VisitorPersonSerl(serializers.ModelSerializer):
    visitor = VisitorBriefSerl()
    person = PersonBriefSerl()

    class Meta:
        model = VisitorPerson
        fields = (
            "id",
            "visitor",
            "person",
        )


class VisitorCarSerl(serializers.ModelSerializer):
    visitor = VisitorBriefSerl()
    car = CarLstSerl()

    class Meta:
        model = VisitorCar
        fields = (
            "id",
            "visitor",
            "car",
        )


class VisitorTeacherSerl(serializers.ModelSerializer):
    visitor = VisitorBriefSerl()
    teacher = TeacherBriefSerl()

    class Meta:
        model = VisitorTeacher
        fields = (
            "id",
            "visitor",
            "teacher",
        )
